/*
*	Project: Aethon
*
*	File: Eye.cpp
*
*	Author: Jonathan Hersack
*
*	Date: 2/15/2009
*
*   Purpose: The Eye contains the look at information for the viewpoint and 
*   the wireframe and activity modifier flags.
*/

#include "../include/Eye.h"

void Eye::update(vector3f modelPosition, vector3f modelDirection)
{
if(getIsActive())
{
	
	float Matrix[16];
	Quaternion tempQuaternion;

	// Make the Quaternions that will represent our rotations
	xRotation.CreateFromAxisAngle(1.0f, 0.0f, 0.0f, modelDirection.v[0]);//pitch
	yRotation.CreateFromAxisAngle(0.0f, 1.0f, 0.0f, modelDirection.v[1]);//heading
	
	// Combine the pitch and heading rotations and store the results in q
	tempQuaternion = xRotation * yRotation;
	tempQuaternion.CreateMatrix(Matrix);
	glLoadIdentity();
	// Let OpenGL set our new prespective on the world!
	glMultMatrixf(Matrix);
	
	// Create a matrix from the pitch Quaternion and get the j vector 
	// for our direction.
	xRotation.CreateMatrix(Matrix);
	lookAt.v[1] = Matrix[9];

	// Combine the heading and pitch rotations and make a matrix to get
	// the i and j vectors for our direction.
	tempQuaternion = yRotation * xRotation;
	tempQuaternion.CreateMatrix(Matrix);
	lookAt.v[0] = Matrix[8];
	lookAt.v[2] = Matrix[10];

	// Translate to our new position.
	glTranslatef(-modelPosition.v[0], -modelPosition.v[1], modelPosition.v[2]);
}//end if
}//end update


